package com.study.lagou.edu;

public class MineMaxGold {


    private static int mineMaxGold(Goldmine[] goldmines, int maxMiners) {
        if (goldmines == null || goldmines.length == 0) {
            return 0;
        }
        if (maxMiners <= 0) {
            return 0;
        }

        int[][] dp = new int[goldmines.length + 1][maxMiners + 1];
        for (int i = 1; i <= goldmines.length; i++) {
            Goldmine goldmine = goldmines[i - 1];
            for (int j = 1; j <= maxMiners; j++) {
                if (j < goldmine.needMiner) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], goldmine.storage + dp[i - 1][j - goldmine.needMiner]);
                }
            }
        }

        return dp[goldmines.length][maxMiners];
    }

    public static void main(String[] args) {
        Goldmine[] goldmines = new Goldmine[]{
                new Goldmine(500, 5),
                new Goldmine(200, 3),
                new Goldmine(300, 4),
                new Goldmine(600, 7),
                new Goldmine(800, 6),
        };

        int miners = 10;
        System.out.println(mineMaxGold(goldmines, miners));
    }
}
